#include "widget.h"
#include "windows.h"
#include <QDebug>
#include <QPainter>
#include <QImage>
#include <QDesktopWidget>

static HWND worker = 0;
static BOOL CALLBACK numWnd(HWND top,LPARAM toppara)
{
	HWND p = FindWindowEx(top,0,L"SHELLDLL_DefView",0);
	if(p!=0)
	{
		worker = FindWindowEx(0,top,L"WorkerW",0);
	}
	return true;
}
Widget::Widget(QWindow *parent):QWindow(parent),store(this)
{
	HWND hwndprog = FindWindow(L"Progman",L"Program Manager");
	SendMessageTimeout(hwndprog,0x052c,0,0,SMTO_NORMAL,1000,0);
	EnumWindows(numWnd,0);
	if(worker == 0)
	{
		abort();
	}
	QWindow * window = QWindow::fromWinId((WId)worker);
	this->setParent(window);
	QDesktopWidget w;
	this->setGeometry(QRect(w.availableGeometry()));
}

Widget::~Widget()
{
}

bool Widget::event(QEvent *e)
{
	if(e->type() == QEvent::Expose || e->type() == QEvent::Resize)
	{
		QRect pos(QPoint(0,0),this->size());
		QImage img("C:/Users/admin/Pictures/p.jpg");
		store.resize(this->size());
		store.beginPaint(pos);
		QPainter paint(store.paintDevice());
		paint.drawImage(10,10,img);
		store.endPaint();
		store.flush(pos);
	}
	return QWindow::event(e);
}



